
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MapReduce implements WritableComparable<MapReduce> {
    private String id;
    private String ids;
    private  String name;
    private  double price;


    public MapReduce() {
    }

    public MapReduce(String id, String ids, String name, double price){
        this.id = id;
        this.ids = ids;
        this.name = name;
        this.price = price;
    }
    public String getId(){
        return id;
    }
    public void setId(String id){
       this.id =id;
    }
    public String getIds(){
        return ids;
    }
    public void setIds(String ids){
       this.ids =ids;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }

    public double getPrice(){
        return price;
    }
    public void setPrice(double price){
        this.price = price;
    }

   //序列化调用的方法
    public void write(DataOutput out) throws IOException {
        out.writeUTF(id);
        out.writeUTF(ids);
        out.writeUTF(name);
        out.writeDouble(price);
    }
    //反序列化调用方法
    public void readFields(DataInput in) throws IOException {
        this.id = in.readUTF();
        this.ids = in.readUTF();
        this.name = in.readUTF();
        this.price = in.readDouble();
    }
    @Override
    public String toString(){
        return this.id +","+ this.ids + ","+ this.name +","+ this.price;
    }

    public int compareTo(MapReduce o) {
        if (this.getPrice() - o.price < 1) {
            return 1;
        } else {
            return -1;
        }
    }
}
